<template>
	<view class="content">
		<view class="tabber_box flexs1">
			<view class="tabber_item" @click='clickbtn(1)' :class="{'chooseactive':typeindex==1}">
				<view>全部订单</view>
				<view class="title_line" v-show="typeindex==1"></view>
			</view>
			<view class="tabber_item" @click='clickbtn(2)' :class="{'chooseactive':typeindex==2}">
				<view>未支付</view>
				<view class="title_line" v-show="typeindex==2"></view>
			</view>
			<view class="tabber_item" @click='clickbtn(3)' :class="{'chooseactive':typeindex==3}">
				<view>已支付</view>
				<view class="title_line" v-show="typeindex==3"></view>
			</view>
		</view>
		<view class="list_box">
			<!-- 全部 -->
			<block v-if="typeindex==1">
				<view class="none_msg" v-if="allorderlist.length == 0">
					<image src="../../static/image/offerxq_img_k@2x.png" mode=""></image>
					<view class="none_title">暂无信息</view>
				</view>
				<view class="list_item" v-for="(item,index) in allorderlist" :key="index" v-else>
					<view class="list_top">
						<view class="list_top_l">订单编号:{{item.order_sn}}</view>
						<!-- 订单状态status: 1:未支付，2:已支付，3:取消 -->
						<view class="list_top_r" v-if='item.status == "1"'>未付款</view>
						<view class="list_top_r" v-if='item.status == "2"'>已付款</view>
						<view class="list_top_r" v-if='item.status == "3"'>已取消</view>
					</view>
					<!-- type 1.课程 2.试卷 3.助攻-->
					<view class="list_content">
						<view class="list_content_l" v-show="item.type!=2">
							<image :src="picture.getImgUrl(item.image)" mode="aspectFit"></image>
						</view>
						<view class="list_content_r">
							<view class="list_content_title">{{item.name}}</view>
							<view class="list_content_money">￥<text style="font-size: 34rpx;">{{item.price}}</text>
							</view>
						</view>
					</view>
					<view class="list_btm">
						<view class="list_btn" v-show="item.status!=1" @click="showModal($event,item.id)"
							data-target="Modal">删除订单</view>
						<block v-if="item.status==1">
							<view class="list_btn" @click="showModal1($event,item.id)" data-target="Modal1">取消订单</view>
							<view class="list_btn1"
								@click="goPay(item.id,item.price,item.order_sn,item.q_id,item.type,item.c_id,item.a_id)">
								立即支付</view>
						</block>
					</view>
				</view>
			</block>
			<!-- 未支付 -->
			<block v-if="typeindex==2">
				<view class="none_msg" v-if="nopayorderlist.length == 0">
					<image src="../../static/image/offerxq_img_k@2x.png" mode=""></image>
					<view class="none_title">暂无信息</view>
				</view>
				<view class="list_item" v-for="(item,index) in nopayorderlist" :key="index" v-else>
					<view class="list_top">
						<view class="list_top_l">订单编号:{{item.order_sn}}</view>
						<view class="list_top_r">未付款</view>
					</view>
					<view class="list_content">
						<view class="list_content_l" v-show="item.type!=2">
							<image :src="picture.getImgUrl(item.image)" mode="aspectFit"></image>
						</view>
						<view class="list_content_r">
							<view class="list_content_title">{{item.name}}</view>
							<view class="list_content_money">￥<text style="font-size: 34rpx;">{{item.price}}</text>
							</view>
						</view>
					</view>
					<view class="list_btm">
						<view class="list_btn" @click="showModal1($event,item.id)" data-target="Modal1">取消订单</view>
						<view class="list_btn1"
							@click="goPay(item.id,item.price,item.order_sn,item.q_id,item.type,item.c_id,item.a_id)">
							立即支付</view>
					</view>
				</view>
			</block>
			<block v-if="typeindex==3">
				<view class="none_msg" v-if="payorderlist.length == 0">
					<image src="../../static/image/offerxq_img_k@2x.png" mode=""></image>
					<view class="none_title">暂无信息</view>
				</view>
				<view class="list_item" v-for="(item,index) in payorderlist" :key="index" v-else>
					<view class="list_top">
						<view class="list_top_l">订单编号:{{item.order_sn}}</view>
						<view class="list_top_r">已付款</view>
					</view>
					<view class="list_content">
						<view class="list_content_l" v-show="item.type!=2">
							<image :src="picture.getImgUrl(item.image)" mode="aspectFit"></image>
						</view>
						<view class="list_content_r">
							<view class="list_content_title">{{item.name}}</view>
							<view class="list_content_money">￥<text style="font-size: 34rpx;">{{item.price}}</text>
							</view>
						</view>
					</view>
					<view class="list_btm">
						<view class="list_btn" @click="showModal($event,item.id)" data-target="Modal">删除订单</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 取消弹窗 -->
		<view class="cu-modal" :class="modalName1=='Modal1'?'show':''">
			<view class="cu-dialog">
				<view class="cu_title">
					<view></view>
					<view class="text-bold cu-item-title1">提示</view>
					<view class="action1" @click="hideModal1">
						<image src="../../static/image/ico_ts_gb@2x.png" mode=""></image>
					</view>
				</view>
				<view class="padding_xl">
					<view class="cu_tip">您确定取消该订单吗？</view>
				</view>
				<view class="button" @click='cancleorder'>
					<view class="cu_btn">确定</view>
				</view>
			</view>
		</view>
		<!-- 删除弹窗 -->
		<view class="cu-modal" :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog">
				<view class="cu_title">
					<view></view>
					<view class="text-bold cu-item-title1">提示</view>
					<view class="action1" @click="hideModal">
						<image src="../../static/image/ico_ts_gb@2x.png" mode=""></image>
					</view>
				</view>
				<view class="padding_xl">
					<view class="cu_tip">您确定删除该订单吗？</view>
				</view>
				<view class="button">
					<view class="cu_btn" @click='deleteclick'>确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		OrderIndex,
		OrderDelete,
		OrderCancel
	} from '@/api/personal.js'
	export default {
		data() {
			return {
				typeindex: 1,

				page: 1,
				limit: 999999,
				allorderlist: [],

				nopaypage: 1,
				nopaylimit: 999999,
				nopayorderlist: [],

				paypage: 1,
				paylimit: 999999,
				payorderlist: [],

				cancleorderid: '', //取消订单的id
				deleteid: '', //删除订单id

				modalName1: null,
				product_star: 5,
				modalName: null,
				seltype: 1
			}
		},
		onLoad() {
			this._getorder()
		},
		onShow() {
			this._getorder()
		},

		methods: {
			_getorder() {
				var status
				var page
				var pageSize
				if (this.typeindex == 1) {
					status = 0
					page = this.page
					pageSize = this.limit
				} else if (this.typeindex == 2) {
					status = 1
					page = this.nopaypage
					pageSize = this.nopaylimit
				} else {
					status = 2
					page = this.paypage
					pageSize = this.paylimit
				}
				// 兄弟当你看到这个段代码的时候，我应该已经离职了
				// 这个项目所有代码我都没有注释，因为我没有注释习惯，我知道BUG太多了，注释不知道从何处下手
				// 项目测试的时候经常出问题，它老是跑不起来，所以我先跑了。。。。
				// 哦，对了，咱们这儿附件软件公司很多都缺技术，你要是换一家还来得及~
				let obj = {
					page: page,
					pageSize: pageSize,
					status: status
				}
				OrderIndex(obj).then(res => {
					if (res.code == 1) {
						if (this.typeindex == 1) {
							if (this.page == 1) {
								this.allorderlist = res.data.data
							} else {
								this.allorderlist = this.allorderlist.concat(res.data.data)
							}
						} else if (this.typeindex == 2) {
							if (this.nopaypage == 1) {
								this.nopayorderlist = res.data.data
							} else {
								this.nopayorderlist = this.nopayorderlist.concat(res.data.data)
							}
							console.log(this.nopayorderlist)

						} else {
							if (this.paypage == 1) {
								this.payorderlist = res.data.data
							} else {
								this.payorderlist = this.payorderlist.concat(res.data.data)
							}
						}
					} else {
						this.$msg(res.msg)
					}
				})
			},
			clickbtn(val) {
				this.typeindex = val
				this._getorder()
			},
			showModal1(e, id) {
				this.cancleorderid = id
				this.modalName1 = e.currentTarget.dataset.target
				console.log(this.modalName1, id);
			},
			hideModal1(e) {
				this.modalName1 = null
			},
			showModal(e, id) {
				this.deleteid = id
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
			deleteclick() {
				this.modalName = null
				let obj = {
					id: this.deleteid
				}
				OrderDelete(obj).then(res => {
					if (res.code == 1) {
						// 取消订单成功后重新请求
						this.$msg(res.msg)
						this._getorder()
					} else {
						this.$msg(res.msg)
					}
				})
			},
			// 课程评价
			chooseType(val) {
				this.seltype = val
			},
			goPay(id, money, orderSn, qid, type, cid, aid) {
				console.log(type);
				// 试卷支付
				if (type == 2) {
					uni.navigateTo({
						url: '../payment/payment?oid=' + id + '&price=' + money + '&orderSn=' + orderSn +
							'&type=1' + '&id=' + qid + '&payment=false'
					})
				} else if (type == 1) {
					// 课程支付
					uni.navigateTo({
						url: '../data/paycenter?orderid=' + id + '&type=' + type + '&id=' + cid

					})
				} else if (type == 3) {
					// 助攻支付
					uni.navigateTo({
						url: '../data/paycenter?orderid=' + id + '&type=' + type + '&id=' + aid
					})
				}
			},
			cancleorder() { //取消订单
				this.modalName1 = null
				let obj = {
					o_id: this.cancleorderid
				}
				OrderCancel(obj).then(res => {
					if (res.code == 1) {
						// 取消订单成功后重新请求
						this._getorder()
					} else {
						this.$msg(res.msg)
					}
				})
			}

		}
	}
</script>

<style>
	.content {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
	}

	.tabber_box {
		width: 100%;
		height: 80rpx;
		margin: auto;
		padding: 0 80rpx;
		background-color: #FFFFFF;
		overflow-x: scroll;
		/* padding-left: 20rpx; */
		position: fixed;
		top: 85rpx;
		/* #ifdef APP-PLUS */
		top: 0;
		/* #endif */
		z-index: 10;
	}

	.tabber_item {
		width: 33%;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		flex-shrink: 0;
	}

	.chooseactive {
		width: 33%;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.title_line {
		width: 60rpx;
		height: 4rpx;
		background: #FFDD47;
		border-radius: 2rpx;
		margin-top: 5rpx;
	}

	.list_box {
		width: 100%;
		/* #ifdef APP-PLUS */
		height: 100%;
		/* #endif */
		height: calc(100% - 100rpx);
		/* height: 100%; */
		margin-top: 100rpx;
		padding-bottom: 30rpx;
		overflow-y: auto;
	}

	.list_item {
		width: 100%;
		height: auto;
		background-color: #FFFFFF;
		padding: 0rpx 30rpx;
		padding-top: 30rpx;
		margin-top: 20rpx;
	}

	.list_top {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 20rpx;
	}

	.list_top_l {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.list_top_r {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FF3B30;
	}

	.list_content {
		width: 100%;
		height: auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #F5F5F5;
	}

	.list_content_l {
		width: 196rpx;
		height: 130rpx;
		/* margin-top: 20rpx; */
		margin-bottom: 30rpx;
	}

	.list_content_l image {
		width: 196rpx;
		height: 130rpx;
		background: #F7F5F6;
		border-radius: 10rpx;
	}

	.list_content_r {
		width: 68%;
		height: auto;
		/* margin-top: 20rpx; */
		margin-bottom: 30rpx;
	}

	.list_content_title {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.list_content_money {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FF3B30;
	}

	.list_btm {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}

	.list_btn {
		width: 120rpx;
		height: 40rpx;
		border: 1rpx solid #CCCCCC;
		border-radius: 4rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.list_btn1 {
		width: 120rpx;
		height: 40rpx;
		background: #FFDD47;
		border-radius: 4rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 40rpx;
	}

	/* 企业评价弹窗 */
	.cu-dialog {
		width: 570rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 10rpx;
	}

	.cu-dialog {
		position: relative;
		display: inline-block;
		vertical-align: middle;
		margin-left: auto;
		margin-right: auto;
		max-width: 100%;
		overflow: hidden;
	}

	.cu-item-title {
		font-size: 32rpx;
	}

	.cu-item-title1 {
		width: 100%;
		font-size: 32rpx;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.action1 image {
		width: 29rpx;
		height: 29rpx;

	}

	.cu_title {
		width: 100%;
		height: 80rpx;
		padding: 0rpx 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #F5F5F5;

	}

	.button {
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.cu_btn {
		width: 250rpx;
		height: 60rpx;
		background: #FFDD47;
		border-radius: 6rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.padding_xl {
		width: 100%;
		height: 120rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
	}

	.cu_start_box {
		width: 100%;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.cu_start_box image {
		width: 39rpx;
		height: 36rpx;
		margin-right: 10rpx;
	}

	.cu_text_area {
		width: 509rpx;
		height: 140rpx;
		background: #F2F2F2;
		padding: 20rpx 20rpx;
	}

	.text_area_class {
		width: 100%;
		height: 100%;
		text-align: left;
		font-size: 26rpx;
	}

	.input_class {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.cu_close {
		width: 60rpx;
		height: 60rpx;
		position: absolute;
		bottom: 25%;
		right: 45%;
	}

	/* 暂无消息 */
	.none_msg {
		width: 100%;
		height: auto;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		margin-top: 300rpx;
	}

	.none_msg image {
		width: 354rpx;
		height: 253rpx;
	}

	.none_title {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		margin-top: 40rpx;
	}

	.cu-modal {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 1110;
		opacity: 0;
		outline: 0;
		text-align: center;
		transform: scale(1.185);
		perspective: 1000px;
		background: rgba(0, 0, 0, .6);
		transition: all .3s ease-in-out 0s;
		pointer-events: none;
	}
	.cu-modal::before{
		content: '';
		display: inline-block;
		height: 100%;
		vertical-align: middle;
	}
	.show {
		opacity: 1;
		-webkit-transition-duration: .3s;
		transition-duration: .3s;
		-ms-transform: scale(1);
		-webkit-transform: scale(1);
		transform: scale(1);
		overflow-x: hidden;
		overflow-y: auto;
		pointer-events: auto;
	}
</style>
